package sm.server.vmOperations;


import com.vmware.vim25.ManagedObjectReference;
import com.vmware.vim25.ObjectSpec;
import com.vmware.vim25.PropertyFilterSpec;
import com.vmware.vim25.PropertySpec;
import com.vmware.vim25.RetrieveOptions;
import com.vmware.vim25.RetrieveResult;
import com.vmware.vim25.ServiceContent;
import com.vmware.vim25.TraversalSpec;
import com.vmware.vim25.VimPortType;

public class DwsDataRetriever {
	public static RetrieveResult retrieveData(ServiceContent _sic,VimPortType _service,
			String[] types, String path,String[] propSepcPathSet
			)throws Exception{
		ManagedObjectReference viewMgrRef = _sic.getViewManager();
		ManagedObjectReference propColl = _sic.getPropertyCollector();
	//	String[] vm ={ "VirtualMachine" };

		ManagedObjectReference sIndex=_sic.getSearchIndex();
		ManagedObjectReference rFolder=_service.findByInventoryPath(sIndex, path);
		
		ManagedObjectReference cViewRef;
		cViewRef = _service.createContainerView(viewMgrRef, rFolder, types, true);
		
		ObjectSpec oSpec = new ObjectSpec();
		oSpec.setObj(cViewRef);
		oSpec.setSkip(true);

		TraversalSpec tSpec=new TraversalSpec();
		tSpec.setName("traverseEntities");
		tSpec.setPath("view");
		tSpec.setSkip(false);
		tSpec.setType("ContainerView");
		oSpec.setSelectSet(new TraversalSpec[]{tSpec});

		PropertySpec pSpec=new PropertySpec();
		pSpec.setType("VirtualMachine");
		pSpec.setPathSet(propSepcPathSet);

		PropertyFilterSpec fSpec=new PropertyFilterSpec();
		fSpec.setObjectSet(new ObjectSpec[]{oSpec});
		fSpec.setPropSet(new PropertySpec[]{pSpec});

		PropertyFilterSpec[] pfs={fSpec};
		RetrieveOptions ro=new RetrieveOptions();
		RetrieveResult props =_service.retrievePropertiesEx(propColl,pfs,ro);
		
		return props;
	}
}
